﻿using System;
using System.Collections.Generic;
using System.Net.Http;
using VoiceAI;
using VoiceAI.VoiceResponse;
using Windows.Data.Json;
using XiaoweiV2;
using XiaoweiV2.ResponseDataTypes;

namespace XiaoweiVoiceAI.ResponseCreators
{
    internal static class OpenAppResponseCreator
    {
        private class OpenAppResponse : IOpenAppResponseData
        {

            public VoiceAI.ResponseType ResponseType => VoiceAI.ResponseType.OpenApp;

            public ErrorCode ErrorCode => ErrorCode.NoError;

            public string RequestText { get; set; }

            public string ResponseText { get; set; }

            public string TTSUrl { get; set; }

            public bool RestoreInHistory => true;

            public object DataContext { get; set; }

            public string AppName { get; set; } = "";

            public AppType AppType => AppType.App;
        }
        public static IResponseData CreateResponseData(XiaoweiVoiceAI xiaoweiVoiceAI, ResponseParam param)
        {
            JsonObject jo = JsonObject.Parse(param.ResponseData);
            string appName = jo.GetNamedString("open_appid", "");
            OpenAppResponse openAppResponse = new OpenAppResponse();
            openAppResponse.RequestText = param.RequestText;
            openAppResponse.ResponseText = "正在打开请稍等";
            openAppResponse.TTSUrl = xiaoweiVoiceAI.TextToVoice("正在打开请稍等");
            openAppResponse.AppName = appName;
            return openAppResponse;
        }
    }
}
